
#include "gtk_ui.hh"

// FIXME: Use gettext!
#define _(a) (a)

MainWindowUI::MainWindowUI ()
{

  int argc = 1;
  const char* args[] = {"", "\0"};
  char** argv = (char**)&args;

  gtk_init (&argc, &argv);

}


void
MainWindowUI::run ()
{

  GdkPixbuf *pixbuf;
  
  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);

  gtk_window_set_title (GTK_WINDOW (window), _("Lympia Shell Manager"));
  gtk_window_set_position (GTK_WINDOW (window), GTK_WIN_POS_CENTER);

  pixbuf = gtk_widget_render_icon (window,\
                                  GTK_STOCK_DIALOG_AUTHENTICATION,\
                                  GTK_ICON_SIZE_MENU,\
                                  NULL);

  gtk_window_set_default_icon (pixbuf);
  g_object_unref (pixbuf);

  g_signal_connect (GTK_WIDGET (window), "destroy",\
                                 G_CALLBACK (MainWindowUI::sigc_destroy), NULL);

  main_vbox = gtk_vbox_new (FALSE, 0);

  /* Window member widget */
  create_main_menu ();

  gtk_container_add (GTK_CONTAINER (window), main_vbox);

  gtk_widget_show_all (window);

  gtk_main ();

}

void
MainWindowUI::create_main_menu ()
{

  GtkWidget *menu_bar;

  GtkWidget *menu_item;
  GtkWidget *menu;

  menu_bar = gtk_menu_bar_new ();
  
  /* Session menu */
    menu = gtk_menu_new ();
    
    menu_item = gtk_menu_item_new_with_mnemonic ("_Manage hosts...");
    gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item);

    menu_item = gtk_separator_menu_item_new ();
    gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item);
    
    menu_item = gtk_image_menu_item_new_from_stock (GTK_STOCK_QUIT, NULL);
    gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item);
    g_signal_connect_swapped (G_OBJECT (menu_item), "activate",\
      G_CALLBACK (gtk_main_quit), NULL);

  menu_item = gtk_menu_item_new_with_mnemonic (_("_Session"));  
  gtk_menu_item_set_submenu (GTK_MENU_ITEM(menu_item), menu);
  gtk_menu_shell_append (GTK_MENU_SHELL (menu_bar), menu_item);
  /* Session menu end */
  
  /* Edit menu */
  menu = gtk_menu_new ();

    menu_item = gtk_image_menu_item_new_from_stock (GTK_STOCK_COPY, NULL);
    gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item);

    menu_item =  gtk_image_menu_item_new_from_stock (GTK_STOCK_PASTE, NULL);
    gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item);

    menu_item = gtk_separator_menu_item_new ();
    gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item);
    
    menu_item =  gtk_image_menu_item_new_from_stock (GTK_STOCK_PREFERENCES,\
                   NULL);
    gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item);

  menu_item = gtk_menu_item_new_with_mnemonic (_("_Edit"));
  gtk_menu_item_set_submenu (GTK_MENU_ITEM(menu_item), menu);
  gtk_menu_shell_append (GTK_MENU_SHELL (menu_bar), menu_item);
  /* Edit menu end */
  
  /* Help menu */
  menu = gtk_menu_new ();

    menu_item = gtk_image_menu_item_new_from_stock (GTK_STOCK_ABOUT, NULL);
    gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item);
  
  menu_item = gtk_menu_item_new_with_mnemonic (_("_Help"));
  gtk_menu_item_set_submenu (GTK_MENU_ITEM(menu_item), menu);
  gtk_menu_shell_append (GTK_MENU_SHELL (menu_bar), menu_item);
  /* Help menu end */
  
  gtk_box_pack_start (GTK_BOX (main_vbox), menu_bar, FALSE, FALSE, 0);

}

void
MainWindowUI::sigc_destroy (GtkObject *object, gpointer user_data)
{

  gtk_main_quit ();

  (void)object;
  (void)user_data;

}

MainWindowUI::~MainWindowUI ()
{}

